<template>
    <div id="dr9">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>运营平台分析</BreadcrumbItem>
            <BreadcrumbItem>日注册用户统计表</BreadcrumbItem>
        </Breadcrumb>
        <div style="padding-right: 20px">
            <DatePicker v-model="startYearMonthDay" type="month" placeholder="选择年月" style="width: 150px"></DatePicker>
            &nbsp;
            <Button type="info" @click="search()">查询</Button>
            <Button type="info" @click="handleDownload()" style="float: right">下载报表</Button>
        </div>
        <Table style="margin-top: 10px" :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
               v-if="data&&data.length>0"></Table>

        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>


    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';
    export default{
        data(){
            return {
                startYearMonthDay: "",
                endDateFlag: "",
                loading: false,
                columns: [
                    {
                        title: '统计日期',
                        key: 'registeTime',
                        width: 150
                    },
                    {
                        title: '司机',
                        key: 'driverCount',
                    },
                    {
                        title: '配件商',
                        key: 'productsBusinessCount',
                    },
                    {
                        title: '修理',
                        key: 'repairCount'
                    },
                    {
                        title: '流动补胎',
                        key: 'tyreRepairCount'

                    },
                    {
                        title: '审车',
                        key: 'vehicleInspectionCount'
                    },
                    {
                        title: '加油',
                        key: 'putOilCount'
                    },
                    {
                        title: '吊车',
                        key: 'hoistCount'
                    },
                    {
                        title: '商家',
                        key: 'businessSum'
                    },
                    {
                        title: '合计',
                        key: 'sum'
                    }
                ],
                data: []
            }
        },
        mounted(){
            this.search();
        },
        methods: {
            search(){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (this.startYearMonthDay) {
                    param.append('startYearMonth', sessionUtils.DateToMonth(this.startYearMonthDay) + "");
                }
                this.loading = true;
                Axios.post(ipServer + "user/selectRegisterUserCount", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                this.data = res.data.data;
                                if (this.data.length == 0)
                                    this.$Message.info("查询数据不存在!");
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            }, handleDownload() {
                this.loading = true;
                const list = this.data;
                require.ensure([], () => {
                    const {export_json_to_excel} = require('../../assets/js/Export2Excel') //这个地址和页面的位置相关，这个地址是Export2Excel.js相对于页面的相对位置
                    const tHeader = ["统计日期", "司机", "配件商", "修理", "流动补胎", "审车", "加油", "吊车", "商家", "合计"]; //这个是表头名称 可以是iveiw表格中表头属性的title的数组
                    const filterVal = ["registeTime", "driverCount", "productsBusinessCount", "repairCount", "tyreRepairCount", "vehicleInspectionCount", "putOilCount", "hoistCount", "businessSum", "sum"]; //与表格数据配合 可以是iview表格中的key的数组
                    const data = this.formatJson(filterVal, list)
                    export_json_to_excel(tHeader, data, '用户签到') //列表excel  这个是导出表单的名称
                    this.loading = false
                })
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => v[j]))
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>